package com.tudouji.project.purchasebill.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.tudouji.framework.aspectj.lang.annotation.Log;
import com.tudouji.framework.aspectj.lang.enums.BusinessType;
import com.tudouji.project.purchasebill.domain.Purchasebillitem;
import com.tudouji.project.purchasebill.service.IPurchasebillitemService;
import com.tudouji.framework.web.controller.BaseController;
import com.tudouji.framework.web.domain.AjaxResult;
import com.tudouji.common.utils.poi.ExcelUtil;
import com.tudouji.framework.web.page.TableDataInfo;

/**
 * 采购单明细Controller
 * 
 * @author tudouji
 * @date 2022-04-11
 */
@RestController
@RequestMapping("/purchasebill/purchasebillitem")
public class PurchasebillitemController extends BaseController
{
    @Autowired
    private IPurchasebillitemService purchasebillitemService;

    /**
     * 查询采购单明细列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Purchasebillitem purchasebillitem)
    {
        startPage();
        List<Purchasebillitem> list = purchasebillitemService.selectPurchasebillitemList(purchasebillitem);
        return getDataTable(list);
    }

    /**
     * 导出采购单明细列表
     */
    @PreAuthorize("@ss.hasPermi('purchasebill:purchasebillitem:export')")
    @Log(title = "采购单明细", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Purchasebillitem purchasebillitem)
    {
        List<Purchasebillitem> list = purchasebillitemService.selectPurchasebillitemList(purchasebillitem);
        ExcelUtil<Purchasebillitem> util = new ExcelUtil<Purchasebillitem>(Purchasebillitem.class);
        return util.exportExcel(list, "purchasebillitem");
    }

    /**
     * 获取采购单明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('purchasebill:purchasebillitem:query')")
    @GetMapping(value = "/{guid}")
    public AjaxResult getInfo(@PathVariable("guid") String guid)
    {
        return AjaxResult.success(purchasebillitemService.selectPurchasebillitemById(guid));
    }

    /**
     * 新增采购单明细
     */
    @Log(title = "采购单明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Purchasebillitem purchasebillitem)
    {
        return toAjax(purchasebillitemService.insertPurchasebillitem(purchasebillitem));
    }

    /**
     * 修改采购单明细
     */
    @Log(title = "采购单明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Purchasebillitem purchasebillitem)
    {
        return toAjax(purchasebillitemService.updatePurchasebillitem(purchasebillitem));
    }

    /**
     * 删除采购单明细
     */
    @Log(title = "采购单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{guids}")
    public AjaxResult remove(@PathVariable String[] guids)
    {
        return toAjax(purchasebillitemService.deletePurchasebillitemByIds(guids));
    }

    /**
     * 删除采购单明细
     */
    @Log(title = "采购单明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/del/{guid}")
    public AjaxResult del(@PathVariable String guid)
    {
        return toAjax(purchasebillitemService.del(guid));
    }
}
